package cn.wolfcode.web.controller;


import cn.wolfcode.domain.Classinfo;
import cn.wolfcode.domain.Courseorder;
import cn.wolfcode.domain.Customer;
import cn.wolfcode.qo.CourseorderQuery;
import cn.wolfcode.service.ClassinfoService;
import cn.wolfcode.service.CourseorderService;
import cn.wolfcode.qo.QueryObject;
import cn.wolfcode.service.CustomerService;
import cn.wolfcode.vo.JsonResult;
import com.github.pagehelper.PageInfo;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Collection;
import java.util.List;

@Controller
@RequestMapping("/courseorder")
public class CourseorderController {

    @Autowired
    private CourseorderService courseorderService;

    @Autowired
    private CustomerService customerService;
    @Autowired
    private ClassinfoService classinfoService;


    @RequiresPermissions(value = {"courseorder:list", "课程订单页面"}, logical = Logical.OR)
    @RequestMapping("/list")
    public String list(Model model, @ModelAttribute("qo") CourseorderQuery qo) {
        PageInfo<Courseorder> pageInfo = courseorderService.query(qo);
        //查询所有客户
        List<Customer> customers = customerService.listAll();
        //查询所有的班级
        List<Classinfo> classinfos = classinfoService.listAll();

        model.addAttribute("customers", customers);
        model.addAttribute("classinfos", classinfos);
        model.addAttribute("pageInfo", pageInfo);
        return "courseorder/list";
    }


    @RequestMapping("/saveOrUpdate")
    @RequiresPermissions(value = {"courseorder:saveOrUpdate", "课程订单新增/编辑"}, logical = Logical.OR)
    @ResponseBody
    public JsonResult saveOrUpdate(Courseorder courseorder) {
        courseorderService.saveOrUpdate(courseorder);

        return new JsonResult();
    }
}
